//
//  FileManager.m
//  MyPopStar
//
//  Created by tarena on 16/1/13.
//  Copyright © 2016年 ssnb. All rights reserved.
//

#import "FileManager.h"

@interface FileManager ()
@property (nonatomic,weak)  NSFileManager *manager;
@property (nonatomic,strong) NSString *documentPath;
@end
@implementation FileManager

-(void)write{
    //在Documents目录下，创建空的fileHandle.txt
    NSString *filePath = [self.documentPath stringByAppendingPathComponent:@"resume.plist"];
    BOOL ret = [self.manager createFileAtPath:filePath contents:nil attributes:nil];
    if (!ret) {
        NSLog(@"fileHandle.txt文件创建失败");
    }
    NSDictionary *dic = [[NSDictionary alloc]init];
    [dic writeToFile:filePath atomically:YES];
    //2. 创建写文件控制器
    NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:filePath];
    
    //3. 初始化需要写入的数据
    NSString *content = @"使用NSFileHandel写入文件内容。。。。。";
    
    NSString *content2=@"追加啦啦啦啦啦了";
    //4. 转换成NSData类型
    NSData *data = [content dataUsingEncoding:NSUTF8StringEncoding];
    
    //5. 将NSData数据，使用写文件控制器将文件内容写入文件
    [fileHandle writeData:data];
    [fileHandle writeData:[content2 dataUsingEncoding:NSUTF8StringEncoding]];
    //6. 关闭对接器
    [fileHandle closeFile];


}
//- (void)savePlist
//{
//    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//    NSString *documentsPath = [paths objectAtIndex:0];
//    NSString *selfInfoPath = [documentsPath stringByAppendingPathComponent:@"ddd"];
//    
//    if ([[NSFileManager defaultManager] fileExistsAtPath:selfInfoPath]){
//        NSMutableArray *mutArrRecord = [[NSMutableArray alloc] initWithContentsOfFile:selfInfoPath];
//        for (int i = 0; i < [mutArrRecord count]; i++){
//            NSData *dateRecord = [mutArrRecord objectAtIndex:i];
//            WeiboUserInfo *weiboUserInfo = [NSKeyedUnarchiver unarchiveObjectWithData:dateRecord];
//            ([weiboUserInfo.m_strDeviceJid isEqualToString:[ABServices currentUserName]])
//            [mutArrRecord removeObjectAtIndex:i];
//            [mutArrRecord writeToFile:selfInfoPath atomically:YES];
//            break;
//        }
//    }
//      [mutArrRecord release];
//}

- ( NSFileManager *)manager {
	if(_manager == nil) {
		_manager = [NSFileManager defaultManager];
	}
	return _manager;
}

- (NSString *)documentPath {
	if(_documentPath == nil) {
		_documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
	}
	return _documentPath;
}

@end
